This month MacSense debuts our new Getting Started column with Part 1 of an 
   introduction to AppleScripting. Parts 2 and 3 will follow in subsequent issues.

Relax.  Don’t be scared.  AppleScript is part of the Macintosh System Software, and that means it’s as easy as pie.  I’ll let you in on a little secret:  AppleScript is the most incredible computer technology of the ’90’s.  In this month’s Getting Started column, you’re going to learn how to get started with AppleScript, and you’re gonna love  it!

But, you ask, isn’t AppleScript a (gasp!) programming language ?  How could Apple expect me to know how to program?  How could it possibly be worth all that trouble?  Read on, and everything will become very clear to you.

Let’s begin by learning the concepts. The purpose of AppleScripting is to automate repetitive tasks.  In some ways, this makes it similar to “QuicKeys” and other macro programs. The System 7.5 Finder can be "scripted" to do virtually anything that you can do with your mouse.  Many applications, including WordPerfect 3.1, Microsoft Word 6, Microsoft Excel 5, FileMaker Pro, and QuarkXPress are fully scriptable. Many of the things these programs do can be activated with AppleScripts (which you can write)—tasks such as opening, searching and formatting documents, copying, moving or backing up files, and exchanging data between programs.

This can be a giant time saver. AppleScripts work by sending “Events,” or messages, to the programs you wish to automate.  It doesn’t use any “hacks” to perform its work, but instead sends commands to your applications which make them do the work for you.  This means that you can write small computer programs which will automatically make your Macintosh applications do whatever you want, automatically.  If you have repetitive tasks that you find yourself performing often, this can be a great time-saver.

Once you get started with AppleScript, you’ll be amazed at how handy (and magical!) it is to quickly whip up tiny Mac programs that can speed your work up.  Here are some quick examples:

    To make your monitor display 8-bit color (256 colors):

Set Monitor Depth 8

    To make your monitor display 4-bit color (16 colors):

Set Monitor Depth 4

    To change your Mac’s speaker’s volume to 3:

Set Volume 3

Simple scripts like this can be part of larger scripts, or simple, “stand-alone” Macintosh applications.  It’s also easy to make a script support drag-n-drop, so that you can drop files and folders on your script and have the script do something to the file, such as back it up.

This month’s MacSense package includes a number of AppleScripts for you to use, including the Monitor Depth and Volume scripts shown above.  If you find some that you really like, you can add them to your Apple Menu Items folder for quick access.  Every online service has an AppleScript Forum, where you can find more scripts which you can use.  

System 7.5 comes with AppleScript and a new version of the Finder which is scriptable.  Purchasing the System 7.5 upgrade is probably the best way to get started with AppleScript, but it’s not the only way.  PlainTalk, which comes with AV Macs, includes AppleScript, and there are several other ways to get it, such as purchasing Apple’s AppleScript Scripter Kit or various other Apple products.  AppleScript is also included with Derrick Schneider’s book, “The Tao of AppleScript”.  To use an AppleScript, you only need to have System 7 or later and the AppleScript extension installed in your Extensions Folder.  To edit scripts, you need an Apple application called “Script Editor,” which comes with System 7.5 and the other AppleScript kits.  Of course, you’ll also need the Application which the script is designed to automate.

AppleScript lets you look at and use a program’s data, too.  You could use it to open every text file on your hard disk, look for a particular word in each file, and copy the paragraph containing that word and the name of the document it came from into a new file.  

You can write scripts to backup your data, or perform some time-consuming task very quickly.  You can also make two or three applications work together through AppleScript.  For instance, FileMaker and Quark XPress are both scriptable.  Many people keep information in databases which they need to print out with desktop publishing software.  Catalogs and telephone books, for instance, can only be produced by combining a database program with a desktop publishing program.

Let’s say you worked for a mail-order company, and you keep information about every single product you sell in a database—the part number, a description, perhaps a picture, and the price.  This information is updated constantly, as different vendors offer new products and different prices.  Every two weeks, this product information needs to be copied into a catalog which you create with Quark XPress. 

For years, a job like this was pure grunt work; you’d have to copy and paste items from FileMaker into Quark one at a time, hundreds of times. With AppleScript, you now don’t have to!  Instead, you can just create an AppleScript which automatically copies information about each product out of the database and pastes it into a Quark XPress document. When the script is finished running, you'll be ready to add graphics and pizzaz, instead of wasting your time copying and pasting. 

Hopefully, this will give you some idea of both the power and ease of AppleScript.  Try “playing” with the AppleScripts included with this month’s issue.  Next month, we’ll go under the hood, and look at the source code behind those scripts.  This will let you customize the scripts so that you can put AppleScript to work.

Marshall Goldberg is a Forum Consultant for the Macintosh Multimedia Forum on America Online. He welcomes feedback at AFCMARS@aol.com.